import Pages from '../../pages/pages.vue'
import { setMenuType, showMsg, getScreensList, deleteScreen } from '../../../vuex/action'
export default {
  name: 'flash-ad-list',
  components: {
    'vue-pages': Pages
  },
  data() {
    return {
      list: [],
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      }
    }
  },
  vuex: {
    actions: {
      xSetMenuType: setMenuType,
      xShowMsg: showMsg,
      xGetScreensList: getScreensList,
      xDeleteScreen: deleteScreen
    }
  },
  ready() {
    this.xSetMenuType('gao')
    this.getList({})
  },
  methods: {
    getList({start=this.pages.start, limit=this.pages.limit}) {
      this.xGetScreensList({
        start: start,
        limit: limit
      })
        .then((data) => {
          this.list = data.list
          this.pages.totalPages = Math.ceil(data.totalCount / limit)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    deleteAd(id) {
      this.xDeleteScreen(id)
        .then((data) => {
          this.getList({})
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  }
}
